package logic

import (
	"context"
	"fmt"
	"manage/models/mysql"
	"strings"

	"manage/managerpc/internal/svc"
	"manage/managerpc/managerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LeaveAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLeaveAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LeaveAddLogic {
	return &LeaveAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 留言
func (l *LeaveAddLogic) LeaveAdd(in *managerpc.LeaveAddRequest) (*managerpc.LeaveAddResponse, error) {
	// todo: add your logic here and delete this line
	if strings.Contains(in.Context, "傻") || strings.Contains(in.Context, "操") || strings.Contains(in.Context, "妈") {
		return nil, fmt.Errorf("您的评论含有敏感词")
	}
	user := mysql.Leave{
		UserId:     int(in.UserId),
		ActivityId: int(in.ActivityId),
		Context:    in.Context,
	}
	mysql.DB.Create(&user)
	return &managerpc.LeaveAddResponse{
		Id: int64(user.ID),
	}, nil
}
